﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Administration.Master" AutoEventWireup="true"
    CodeBehind="RoleAssignment.aspx.cs" Inherits="ASB.CC.Web.Admin.RoleAssignment" %>

<%@ Register Src="../UserControls/Pager.ascx" TagName="Pager" TagPrefix="cc" %>
<asp:Content ContentPlaceHolderID="Header" runat="server">

    <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="../js/jquery-ui.min.js" type="text/javascript"></script>

    <script src="../js/entity.js.aspx" type="text/javascript"></script>

    <script type="text/javascript">

        $(function() {

            $(".user-cil").children().first().autocomplete({
                source: "/cilsearch.aspx",
                minLength: 2,
                select: function(event, ui) {
                    //ui.item.value
                    var params = '{value:"' + ui.item.value + '"}';
                    $.ajax({
                        type: "POST",
                        async: false,
                        url: "/cilsearch.aspx/GetRolesByNameEN",
                        data: params,
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        success: function(result) {
                            //alert(result.d);
                            var ids = result.d.split(';');
                            $("input:checkbox").each(function() {
                                var cv = $(this).attr('value');
                                $(this).attr("checked", '');
                                for (i = 0; i < ids.length; i++) {
                                    if (cv == ids[i]) {
                                        $(this).attr("checked", 'checked');
                                        break;
                                    }
                                }
                            });

                        },
                        error: function(xhr, msg, e) {
                            //alert(msg);
                        }
                    });
                }
            });

        });
    </script>

</asp:Content>
<asp:Content ContentPlaceHolderID="Sitemap" runat="server">
    &nbsp;&raquo;&nbsp;Administration&nbsp;&raquo;&nbsp;Role Assignment (<%=GetModuleText()%>)
</asp:Content>
<asp:Content ContentPlaceHolderID="Tab" runat="server">
    <%=Resources.PageTitles.RoleAssignment %>
    (<%=GetModuleText()%>)
</asp:Content>
<asp:Content ContentPlaceHolderID="Utility" runat="server">
    <div class="formbox_float_lft">
        <asp:Button ID="btnAdd" runat="server" CssClass="entity-add" />
    </div>
    <div class="formbox_float_rgt">
        <asp:TextBox ID="txtSearch" runat="server" CssClass="txtbox width140 entity-search-text"
            ToolTip="CIL,Roles"></asp:TextBox>
        <asp:Button ID="btnSearch" runat="server" CssClass="entity-search" />
        <asp:Button ID="btnClear" runat="server" CssClass="entity-clear" />
        <asp:Panel ID="gridPanel" runat=server CssClass="formbox_float_lft" >
         <asp:CheckBox runat="server" ID="admin" Text=" Is Admin" OnCheckedChanged="admin_CheckedChanged"
            AutoPostBack="true"/>
        </asp:Panel>
       
    </div>
</asp:Content>
<asp:Content ContentPlaceHolderID="Main" runat="server">
    <asp:GridView ID="gvMain" runat="server" DataSourceID="edsMain" AllowPaging="true"
        AllowSorting="true" AutoGenerateColumns="False" CssClass="tablestyle">
        <RowStyle CssClass="tbody" />
        <HeaderStyle CssClass="thead" ForeColor="#ffffff" />
        <Columns>
            <asp:BoundField DataField="EmployeeNo" HeaderText="Employee No<br/>员工号" SortExpression="EmployeeNo"
                HtmlEncode="false" ItemStyle-Width="9%" />
            <asp:BoundField DataField="NameEN" HeaderText="CIL<br/>员工CIL" SortExpression="NameEN"
                HtmlEncode="false" ItemStyle-Width="12%" />
            <asp:BoundField DataField="NameCN" HeaderText="Display Name<br/>用户显示名" SortExpression="NameCN"
                HtmlEncode="false" ItemStyle-Width="12%" />
            <asp:TemplateField HeaderText="Roles<br/>用户现有角色">
                <ItemTemplate>
                    <asp:Repeater runat="server" DataSource='<%# GetRoles(GetDataItemX()) %>'>
                        <ItemTemplate>
                            <%#Eval("Name") %>
                            [<%#Eval("BelongsTo") %>],
                        </ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Is Admin<br/>是否是管理员">
                <ItemTemplate>
                    <%# GetIsAdmin(IsAdmin(GetDataItemX()))%>
                </ItemTemplate>
                <ItemStyle Width="9%" />
            </asp:TemplateField>
            <asp:ActionField HeaderText="Action<br />操作" ShowViewButton="true" ShowModifyButton="true"
                HeaderStyle-CssClass="entity-action" ItemStyle-Width="60" />
        </Columns>
        <PagerTemplate>
            <cc:Pager runat="server" />
        </PagerTemplate>
    </asp:GridView>
    <asp:DetailsView ID="dvMain" runat="server" DataKeyNames="EmployeeNo" AutoGenerateRows="False"
        DataSourceID="edsMain" CssClass="tablestyle2">
        <HeaderStyle CssClass="tablestyle2_Title"></HeaderStyle>
        <HeaderTemplate>
            <%=Resources.PageTitles.RoleAssignment %>
            (<%=GetModuleText()%>)
        </HeaderTemplate>
        <FieldHeaderStyle CssClass="tablestyle2_tdTitle" />
        <Fields>
            <asp:TemplateField HeaderText="Employee No (员工号)">
                <ItemTemplate>
                    <%#Eval("EmployeeNo") %></ItemTemplate>
                <InsertItemTemplate>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:CustomizeBoundField DataField="NameEN" HeaderText="CIL (CIL号)" ItemStyle-CssClass="entity-notnull-check entity-length-check user-cil"
                MaxLength="50" />
            <asp:TemplateField HeaderText="Roles (角色)">
                <ItemTemplate>
                    <asp:Repeater runat="server" DataSource='<%# GetRoles(GetDataItemX()) %>'>
                        <ItemTemplate>
                            <b>
                                <%#Eval("BelongsTo") %></b>
                            <%#Eval("Name") %>
                            [<%#Eval("Description") %>] <span class="<%#GetRoleStyle(Eval("IsAdmin")) %>"></span>
                            <br />
                        </ItemTemplate>
                    </asp:Repeater>
                </ItemTemplate>
                <InsertItemTemplate>
                    <asp:Repeater runat="server" DataSourceID="edsRoles">
                        <ItemTemplate>
                            <input type="checkbox" name="ChooseRoles" value="<%#Eval("RoleID") %>"></input><b><%#Eval("BelongsTo") %></b>
                            <%#Eval("Name") %>
                            [<%#Eval("Description") %>] <span class="<%#GetRoleStyle(Eval("IsAdmin")) %>"></span>
                            <br />
                        </ItemTemplate>
                    </asp:Repeater>
                </InsertItemTemplate>
                <EditItemTemplate>
                    <asp:Repeater runat="server" DataSourceID="odsRoles">
                        <ItemTemplate>
                            <input type="checkbox" name="ChooseRoles" value="<%#Eval("RoleID") %>" <%#Eval("Checked")%> /><b><%#Eval("BelongsTo") %></b>
                            <%#Eval("Name") %>
                            [<%#Eval("Description") %>] <span class="<%#GetRoleStyle(Eval("IsAdmin")) %>"></span>
                            <br />
                        </ItemTemplate>
                    </asp:Repeater>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:ActionField ShowEditButton="true" ShowInsertButton="true" ShowInsertMoreButton="true"
                ShowCloseButton="true" />
        </Fields>
    </asp:DetailsView>
    <%--数据源--%>
    <asp:EntityDataSource ID="edsMain" runat="server" ConnectionString="name=CCEntities"
        DefaultContainerName="CCEntities" EntitySetName="Employees" Include="Roles" EnableInsert="True"
        EnableUpdate="True" Where="it.IsEnabled=true and it.IsActived=true">
    </asp:EntityDataSource>
    <asp:ObjectDataSource ID="odsRoles" runat="server" TypeName="ASBCC.Business.RoleAssignmentHelper"
        SelectMethod="GetModuleRoles">
        <SelectParameters>
            <asp:ControlParameter ControlID="dvMain" Name="employeeNo" PropertyName="DataKey.Value"
                Type="String" />
            <asp:QueryStringParameter Name="belongsTo" QueryStringField="sys" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:EntityDataSource ID="edsRoles" runat="server" ConnectionString="name=CCEntities"
        DefaultContainerName="CCEntities" EntitySetName="Roles" OrderBy="it.BelongsTo,it.IsAdmin"
        Where="!it.Disabled  and it.Description != '+pcat+' and it.Description != '+country+' and  it.BelongsTo in {{{0}}}"
        OnLoad="edsRoles_Load">
    </asp:EntityDataSource>
</asp:Content>
